#include "beginwidget.h"
#include "ui_beginwidget.h"
#include"mainwindow.h"
#include"stopwidget.h"
#include<mybtn.h>
#include<QPainter>
#include<QTimer>

BeginWidget::BeginWidget(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::BeginWidget)
{
    ui->setupUi(this);
    setFixedSize(680,920);

    mw=new MainWindow(this);

    MyBtn *btn_begin=new MyBtn(":/Img/btn_4.jpg");
    btn_begin->setParent(this);
    btn_begin->move(this->width()*0.5-btn_begin->width()*0.5,560);

    MyBtn *btn_exit=new MyBtn(":/Img/btn_5.jpg");
    btn_exit->setParent(this);
    btn_exit->move(this->width()*0.5-btn_begin->width()*0.5,690);

    connect(btn_begin,&MyBtn::clicked,[=](){

        btn_begin->zoom1();
        btn_begin->zoom2();

        QTimer::singleShot(200,this,[=]{
            mw->show();
            this->hide();
        });



    });
    connect(btn_exit,&MyBtn::clicked,[=](){

        btn_exit->zoom1();
        btn_exit->zoom2();

        QTimer::singleShot(200,this,[=]{
            this->close();
        });


    });

    connect(mw,&MainWindow::on_btn_home_clicked,[=](){

        this->show();
        mw->close();
    });

    connect(ui->actionstart,&QAction::triggered,[=](){
        mw->show();
        this->hide();
    });
    connect(ui->actionexit,&QAction::triggered,[=](){
        this->close();
    });



}

BeginWidget::~BeginWidget()
{
    delete ui;
}

void BeginWidget::paintEvent(QPaintEvent *event){
    QPainter bpainter(this);
    QPixmap bpix;
    bpix.load(":/Img/bg4.jpg");
    bpainter.drawPixmap(0,0,this->width(),this->height(),bpix);

    bpainter.fillRect(bpix.rect(),QColor(255,255,255,50));


}
